package com.dzsw.javabase.list;

import com.google.common.base.Strings;

import java.util.List;
import java.util.ArrayList;

public class ListInsertSample {

    public static void main(String[] args) {
        test1();
    }

    public static void test0() {
        List<String> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            list.add(Strings.padStart("" + i, 3, '0') + "_str");
        }
        list.add(4, Strings.padStart("10", 3, '0') + "_str");

        list.stream().forEach(System.out::println);
    }

    public static void test1() {
        int pageSize = 64;
        for (int i = 0; i < 300; i++) {
            int[] pageLine = getPageLine(i + 1, pageSize);
            System.out.println(Strings.lenientFormat("INDEX=%s, PAGE=%s, LINE=%s, VALUE=%s",
                     i + 1,
                    pageLine[0],
                    pageLine[1],
                    (pageLine[0] - 1) * pageSize + pageLine[1])
            );
        }

    }

    public static int[] getPageLine(int rowNum, int pageSize) {
        int page;
        int line;

        page = rowNum / pageSize;
        line = rowNum % pageSize;

        if (line > 0) {
            page++;
        } else {
            line = pageSize;
        }

        return new int[] { page, line };
    }
}
